package com.lemo.card;

import java.math.BigDecimal;

public class Main {

    public static void main(String[] args) {
        BankCard bankCard = new BankCard();
        bankCard.addListener(new WifeListener() {
            @Override
            public BigDecimal addEvent(HusbandEvent event, BigDecimal income) {
                BigDecimal store = event.getBankCard().getStore();
                if (store.compareTo(BigDecimal.ZERO) == 1) {
                    if (income.compareTo(BigDecimal.ZERO) == 0) {
                        System.out.println("收入" + income);
                    }
                    if (income.compareTo(BigDecimal.ZERO) == 1) {
                        System.out.println("收入" + income);
                    }
                    if (income.compareTo(BigDecimal.ZERO) == -1) {
                        System.out.println("支出" + income.abs());
                    }
                    store = store.add(income);
                } else {
                    if (income.compareTo(BigDecimal.ZERO) == -1) {
                        System.out.println("支出超出存款" + income.abs());
                    }
                }
                return store;
            }
        });
        for (int i = 0; i < 100; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int i = 0; i < 10000; i++) {
                        BigDecimal store = bankCard.income(new BigDecimal("-1000"));
                        System.out.println("存款" + store);
                    }
                }
            }).start();
        }
//        BigDecimal store = bankCard.income(new BigDecimal("-1000"));
//        System.out.println("存款" + store);
//        BigDecimal store1 = bankCard.income(new BigDecimal("-1000"));
//        System.out.println("存款" + store1);

    }
}
